package com.example.service;

import java.util.List;

import javax.management.Query;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.Mapper.cgxjdao;
import com.example.pojo.Gongyingshang;
import com.example.pojo.Materialzhu;
import com.example.pojo.Xs_bjinfo;
import com.example.pojo.inquiry;
import com.example.pojo.inquirycong;
import com.example.vo.PageBean;
import com.example.vo.cgxjvo;
import com.example.vo.gysvo;


@Service
public class cgxjbiz {
	@Autowired 
	cgxjdao dao;
	
	/**
	 * 分页查询
	 * @param page
	 * @return
	 */
	public PageBean querybypage(int pagenum,int pagesize)
	{	
		PageBean pb=new PageBean();
		pb.setPagenum(pagenum);
		pb.setPagesize(pagesize);
		pb.setRowcount(dao.querycount());
		List<inquiry> ins = dao.querybypage((pagenum-1)*pagesize,pagesize);
		pb.setPagedata(ins);
		return pb;
	}
	
	/**
	 * 通过id查询
	 * @param id
	 * @return
	 */
	public int querybyid(String id)
	{
		return dao.querybyid(id);		 	
	}
	
	/**
	 * 查询询价表的历史记录
	 * @return
	 */
	public List<cgxjvo> queryhistory(String customerid)
	{
		return dao.queryhistory(customerid);
	}
	
	/**
	 * 查询订单表的历史记录
	 * @return
	 */
	public List<cgxjvo> queryhistory1(String customerid)
	{
		return dao.queryhistory1(customerid);
	}
	
	/**
	 * 查询入库单的历史记录
	 * @return
	 */
	public List<cgxjvo> queryhistory2(String customerid)
	{
		return dao.queryhistory2(customerid);
	}
	/**
	 * 查询所有供应商信息
	 * @return
	 */
	 public List<Gongyingshang> querygys()
	 {
		return dao.querygys();
		 
	 }
	 
	 /**
	 * 通过id查询所有供应商信息
	 * @return
	 */
	 public gysvo querygysbyid(String GYSid){
		return dao.querygysbyid(GYSid);
	 }
	 
	 /**
	 * 查询所有物料信息
	 * @return
	 */
	 public List<Materialzhu> querywl()
	 {
		return dao.querywl();
	 }
	 

	 /**
	 * 通过id查询所有物料信息
	 * @return
	 */
	 public List<Materialzhu> querywlbyid(String prodId)
	 {
		return dao.querywlbyid(prodId);
		 
	 }
	
	/**
	 * 新增
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void addxj(inquiry in)
	{
		if (dao.querybyid(in.getBillno())<=0) {
			dao.addxj(in);
			dao.addxj1(in);
		}else{
			dao.deletexjcong(in.getBillno());
			dao.deletexj(in.getBillno());
			dao.addxj(in);
			dao.addxj1(in);
		}
	}
	
	/**
	 * 修改审核状态
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void updateshzt(String id)
	{
		dao.updateshzt(id);
	}
	
	/**
	 * 修改反审核状态
	 * @param in
	 */
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void updateshzt1(String id)
	{
		dao.updateshzt1(id);
	}
	/**
	 * 删除表
	 * @param billno
	 */
	
	@Transactional(propagation=Propagation.REQUIRED,isolation=Isolation.READ_COMMITTED)
	public void deletexj(String billno)
	{	
		dao.deletexjcong(billno);//从
		dao.deletexj(billno);//主
	}
}
